package xlist

import "strconv"

// 快速将[]int、[]float64、[]uint、[]string等转换为[]string
//
//	num	待转换的数字切片
func Num2Str(num any) []string {
	switch input := num.(type) {
	case []int8:
		ret := make([]string, len(input))
		for i, v := range input {
			ret[i] = strconv.FormatInt(int64(v), 10)
		}
		return ret
	case []uint8:
		ret := make([]string, len(input))
		for i, v := range input {
			ret[i] = strconv.FormatUint(uint64(v), 10)
		}
		return ret
	case []int16:
		ret := make([]string, len(input))
		for i, v := range input {
			ret[i] = strconv.FormatInt(int64(v), 10)
		}
		return ret
	case []uint16:
		ret := make([]string, len(input))
		for i, v := range input {
			ret[i] = strconv.FormatUint(uint64(v), 10)
		}
		return ret
	case []int32:
		ret := make([]string, len(input))
		for i, v := range input {
			ret[i] = strconv.FormatInt(int64(v), 10)
		}
		return ret
	case []uint32:
		ret := make([]string, len(input))
		for i, v := range input {
			ret[i] = strconv.FormatUint(uint64(v), 10)
		}
		return ret
	case []int:
		ret := make([]string, len(input))
		for i, v := range input {
			ret[i] = strconv.Itoa(v)
		}
		return ret
	case []uint:
		ret := make([]string, len(input))
		for i, v := range input {
			ret[i] = strconv.FormatUint(uint64(v), 10)
		}
		return ret
	case []int64:
		ret := make([]string, len(input))
		for i, v := range input {
			ret[i] = strconv.FormatInt(v, 10)
		}
		return ret
	case []uint64:
		ret := make([]string, len(input))
		for i, v := range input {
			ret[i] = strconv.FormatUint(v, 10)
		}
		return ret
	case []float32:
		ret := make([]string, len(input))
		for i, v := range input {
			ret[i] = strconv.FormatFloat(float64(v), 'f', -1, 32)
		}
		return ret
	case []float64:
		ret := make([]string, len(input))
		for i, v := range input {
			ret[i] = strconv.FormatFloat(v, 'f', -1, 64)
		}
		return ret
	case []string:
		return input
	case []bool:
		ret := make([]string, len(input))
		for i, v := range input {
			ret[i] = "false"
			if v {
				ret[i] = "true"
			}
		}
		return ret
	}
	return nil
}
